# -*- coding:utf-8 -*-
import csv
import xlrd
from pandas import pd
import numpy as np

"""
r   读   报错  
r+ 读写  报错  覆盖
w   写   创建  覆盖
w+ 读写  创建  覆盖
a   写   创建  追加
a+ 读写  创建  追加

"""

# dict数据保存csv
def save_csv(dict_data: dict):
    with open("result_222.csv", 'a', encoding="utf-8-sig", newline='') as csvfile:
        fileheader = ["code", "name", "title", "no", "relation", "company_liaison", "time", "site",
                      "liaison", "content", "appendix", "date"]
        writer = csv.DictWriter(csvfile, fieldnames=fileheader)
        writer.writerow(dict_data)

# 写csv
with open("result.csv", 'a+', encoding="utf-8-sig", newline='') as f:
    csv_writer = csv.writer(f)
    csv_writer.writerow(["a", "b"])

# 读csv跳过第一行next(f)
with open("result.csv", 'r', encoding="utf-8-sig", newline='') as f:
    next(f)
    reader = csv.reader(f)
    for line in reader:
        pass

# 读xls
data = xlrd.open_workbook("aa.xls")
table = data.sheets()[0]
for rownum in range(table.nrows):
    if rownum > 0:
        id = table.row_values(rownum)[0]
        url = table.row_values(rownum)[1]

# pandas
df = pd.read_excel("高管名单(2).xlsx")
df1 = pd.read_csv("result_3.csv")
source = np.array(df1['c'])
target = np.array(df['Name'])
# 出现频率
dict(df1['a'].value_counts())
# 分组
for i,j in df1.groupby('a'):
    for ii, jj in j.groupby('d'):
        pass